//Copyright (c) Microsoft Corporation.  All rights reserved.

using System;
using System.Collections.Generic;
using System.Text;
using Eas.WebCrawler.Interfaces;

namespace Eas.WebCrawler.PlugIns.TemporaryStorage {

    /// <summary>A <see cref="ConditionalStorageFactory"/> that uses different delegated factories depending on whether or not the current web request is returning a text or binary response.</summary>
    /// <remarks>The thought here is that text (html) responses will be smaller than binary (image, movie) responses, so we can use the appropriate factory here.</remarks>
    public class IsTextResponseConditionalFactory : Eas.WebCrawler.PlugIns.TemporaryStorage.ConditionalStorageFactory{

        /// <summary>Constructs a <see cref="IsTextResponseConditionalFactory"/> from two other factories that are used depending on if the web response is text or not.</summary>
        /// <param name="trueFactory">The factory to use for text responses.</param>
        /// <param name="falseFactory">The factory to use for binary responses.</param>
        public IsTextResponseConditionalFactory(Eas.WebCrawler.Interfaces.TemporaryStorageFactory trueFactory, Eas.WebCrawler.Interfaces.TemporaryStorageFactory falseFactory) 
        : base(trueFactory, falseFactory){ }
        
        /// <summary>Checks whether the current response is text or not.</summary>
        /// <param name="processingState">The details of the current request.</param>
        /// <returns><code>true</code> if the current request is text, otherwise <code>false</code>.</returns>
        protected override bool ConditionalCheck(ProcessingState processingState) {
            return processingState.IsTextResponse;
        }

    }
}
